const axios = require('axios');
export default {
  mode: 'universal',
  /*
  ** Headers of the page
  */
  head: {
    title: process.env.npm_package_name || '',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: process.env.npm_package_description || '' }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ],
    script: [
//    {src: 'https://hm.baidu.com/hm.js?258eb7d85439a9dfc724bd283d9e6c55'} /*引入百度统计的js*/
      // {src: '~/plugins/layer.js'}, /*引入百度统计的js*/
    ]
  },
  generate: {
    fallback:true,
    fallback:'/404.html',
    interval:150,
    routes: function () {
      return axios.get('https://exam.zhonghaiqihang.com/PInterface/Info/allInfoData')
        .then((res) => {
        let v1 = res.data[0].info;
            let v2 = res.data[1].info;
            let v3 = res.data[2].info;

            let v4 = v1.concat(v2);
            let v5 = v4.concat(v3);
        return v5.map((user) => {
          return {
            route: '/xq/' + user.id,
            payload: user
          }
        })
    })
    }

  },

  // },
  /*
  ** Customize the progress-bar color
  */
  loading:'~/components/loading.vue',
  /*
  ** Global CSS
  */
  css: [
    // 'assets/page-transletion.css',
    'element-ui/lib/theme-chalk/index.css',
    "@assets/css/index.css",
    'swiper/dist/css/swiper.css'
  ],
  /*
  ** Plugins to load before mounting the App
  */
  plugins: [
    // { src: "~/plugins/baidu.js"},
    '~/plugins/heart.js',
    // '~/plugins/foot.js',
    // { src: "~/plugins/layer.js",ssr:false},
    { src: "~/plugins/vue-swiper.js",ssr:false},
    { src: '~/plugins/element-ui.js', ssr: false}
  ],
  /*
  ** Nuxt.js dev-modules
  */
  buildModules: [
  ],
  /*
  ** Nuxt.js modules
  */
  modules: [
    '@nuxtjs/axios',
    '@nuxtjs/proxy'
  ],
  axios: {
    proxy: true
  },
  proxy: {
    '/api': {
      target: 'https://exam.zhonghaiqihang.com/',
      pathRewrite: {
        '^/api' : '/'
      }
    }
  },
  router:{
    middleware: 'stats',
    extendRoutes(routes, resolve) {
      let index = routes.findIndex(route => route.name === 'Mobile')
      for(let i=0;i<routes.length;i++){
        if(routes[i].name=='Mall'||routes[i].path =='/PersonalCenter'||routes[i].name=='Login'||routes[i].path=='/Mobile'||routes[i].name=='Success'||routes[i].name=='Header'||routes[i].path =='/CpersonalCenter'){
        }
        else{
          routes[i] = {
            ...routes[i],
            components: {
          default: routes[i].component,
              top: resolve(__dirname, 'pages/Header.vue')
          },
          chunkNames: {
            top: 'pages/Header'
          }
        }
        }
      }

    }
  },

  /*
  ** Build configuration
  */
  build: {
	vendor: ['element-ui'],
    extractCSS: { allChunks: true },
    /*
    ** You can extend webpack config here
    */
    extend (config, ctx) {
    }
  }
}
